<script lang="ts">
import { defineComponent, onMounted, onUnmounted } from "vue";
import { useDialog } from "naive-ui";
import type { DialogApi } from "naive-ui";

// 类型声明扩展
declare global {
  interface Window {
    $dialog?: DialogApi;
  }
}

export default defineComponent({
  name: "DialogContent",
  setup() {
    const dialog = useDialog();

    // 组件挂载时注册全局变量
    onMounted(() => {
      if (import.meta.env.PROD) {
        console.warn("Avoid using window.$dialog in production");
      }
      window.$dialog = dialog;
    });

    // 组件卸载时清理
    onUnmounted(() => {
      delete window.$dialog;
    });

    // 返回空渲染函数（无渲染组件）
    return () => null;
  }
});
</script>
